<template>
  <div>
    <div class="strategyFatherBox">
      <!-- <el-button type="primary" icon="el-icon-upload" size='small' @click="uploadFile">上传文件</el-button> -->
      <el-button type="primary" icon="el-icon-upload" size='small' @click="uploadFileChunk">上传文件</el-button>
    </div>
    <el-table size='mini' ref="multipleTable" :data="updateInfo" tooltip-effect="dark" :default-sort="{prop: 'date', order: 'descending'}">
      <el-table-column prop="name" align='center' :label="$t('操作系统名称')" min-width="200">
        <template slot-scope="scope">
          <tooltip :copyText="scope.row.rootfs_name" class="wid190">
          </tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="name" align='center' :label="$t('操作系统版本')" min-width="200">
        <template slot-scope="scope">
          <tooltip :copyText="scope.row.rootfs_version" class="wid190">
          </tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="name" align='center' :label="$t('内核名称')" min-width="200">
        <template slot-scope="scope">
          <tooltip :copyText="scope.row.kernel_name" class="wid190">
          </tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="name" align='center' :label="$t('内核版本')">
        <template slot-scope="scope">
          <tooltip :copyText="scope.row.kernel_version" class="wid190">
          </tooltip>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="version" align='center' label="版本" min-width="200"></el-table-column> -->
      <el-table-column prop="date" align='center' :label="$t('更新时间')" min-width="200"></el-table-column>
      <el-table-column prop="right" align='center' fixed="right" :label="$t('操作')" width="80">
        <template slot-scope="scope">
          <el-button type="success" plain size="mini" v-if="scope.row.status === 'enable'" @click="uploadSystem(scope.row)">{{ $t('应用') }}</el-button>
          <!-- <el-button type="danger" plain size="mini" v-if="scope.row.status === 'enable'" @click="deleteFile(scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- <upload-file v-if="uploadFileVisible" ref="refUploadFileVisible"></upload-file> -->
    <!-- <upload-file-chunk v-if="uploadFileChunkVisible" ref="refUploadFileChunkVisible"></upload-file-chunk> -->
  </div>
</template>
<script>

import { getSysUpdateInfo, sysUpgrade } from '@/api/system/update'
// import uploadFile from './co/mponents/uploadFile'
// import uploadFileChunk from './components/uploadFileChunk'
import Middle from '@/utils/middle.js'
export default {
  // components: { uploadFile, uploadFileChunk },
  name: 'SystemUpgrade',
  data () {
    return {
      uploadFileVisible: false,
      uploadFileChunkVisible: false,
      updateInfo: []
    }
  },
  mounted () {
    getSysUpdateInfo().then(res => {
      if (res.status === 0) {
        this.updateInfo = res.info
      }
    })
    const _that = this
    Middle.$on('uploadSysList', () => {
      _that.listData()
    })
  },
  methods: {
    uploadFile () {
      this.uploadFileVisible = true
      this.$nextTick(() => {
        this.$refs.refUploadFileVisible.init()
      })
    },
    uploadFileChunk () {
      Middle.$emit('uploadSysFile')
      // this.uploadFileChunkVisible = true
      // this.$nextTick(() => {
      //   this.$refs.refUploadFileChunkVisible.init()
      // })
    },
    uploadSystem (row) { // 请勿断电或手动重启设备等待设备重启自行启动
      this.$confirm(this.$t('请勿断电或手动重启设备等待设备重启自行启动'), this.$t('提示'), {
        closeOnClickModal: false,
        confirmButtonText:this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        confirmButtonClass: 'confirmButton',
        cancelButtonClass: 'confirmCancelButton',
        type: 'warning'
      }).then(() => {
        sysUpgrade({ rootfs_version: row.rootfs_version, kernel_version: row.kernel_version }).then(res => {
          if (res.status === 0) {
            this.$messages.success(this.$t('应用成功'))
            this.listData()
          }
        })
      })
    },
    // deleteFile (row) {
    //   delFirmwareInfo({ name: row.name, type: row.type }).then(res => {
    //     if (res.status === 0) {
    //       this.$message({
    //         message: '删除成功',
    //         type: 'success'
    //       })
    //       this.listData()
    //     }
    //   })
    // },
    // 列表
    listData () {
      getSysUpdateInfo().then(res => {
        if (res.status === 0) {
          this.updateInfo = res.info
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.upgradeButton {
  color: #409eff;
}
</style>
